part of leancloud_rest_api;

abstract class LraBaseModel {
  String? className;
  String? objectId;
  DateTime? createdAt;
  DateTime? updatedAt;

  LraBaseModel({this.className, this.objectId, this.createdAt, this.updatedAt});

  dynamic fromJson(Map<dynamic, dynamic> data) {
    objectId = data['objectId'];
    createdAt = data['createdAt'];
    updatedAt = data['updatedAt'];
  }

  static T? decodeNestedObject<T>(dynamic json, String key, Function fromJson) {
    var data = json[key];
    if (data != null && data is Map) {
      if (data.containsKey('__type')) {
        return fromJson(data); // 只有 objectId
      } else if (data['key'] == key) {
        return fromJson(data['value']);
      }
    }
    return null;
  }
}
